package com.js.admin.mapper;

import com.js.admin.entity.BaseUser;
import com.js.common.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author： ygl
 * @date： 2018/10/29
 * @Description：
 */
public interface BaseUserMapper extends BaseMapper<BaseUser> {

    /**
     * 通过角色ID查询 用于该角色的用户
     * @param groupId
     * @return
     */
    @Select("select u.username,u.name,u.id from base_user u left join  base_group_member gm" +
            " on gm.user_id = u.id where gm.group_id = #{groupId}")
    List<BaseUser> selectMemberByGroupId(@Param("groupId") String groupId);

    /**
     *
     * @param groupId
     * @return
     */
    @Select(" select u.username,u.name,u.id from base_user u left join base_group_leader gm " +
            " on gm.user_id = u.id where gm.group_id = #{groupId}")
    List<BaseUser> selectLeaderByGroupId(@Param("groupId") String groupId);

    /**
     *
     * @param userId
     * @return
     */
    @Select("select bd.id from base_depart bd inner join base_position_depart bpd" +
            " on bpd.depart_id = bd.id " +
            " inner join base_position_user bpu " +
            " on bpd.position_id = bpu.position_id " +
            " where bpu.user_id = #{userId}")
    List<String> selectUserDataDepartIds(String userId);
}
